﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Windows.Forms;
using SpicIE;

namespace TabSaver
{
    [ComVisible(true),
    ClassInterfaceAttribute(ClassInterfaceType.AutoDual),
    GuidAttribute(TabSaver.PLUGIN_GUID),
    ProgIdAttribute(TabSaver.PLUGIN_PROGID)]
    public class TabSaver : SpicIE.Host
    {
        public const string PLUGIN_GUID = "76447852-8B46-4436-8738-3BF2DDAF9A7F";
        public const string PLUGIN_PROGID = "TabSaver.SpicIE";

        public static TabSaver HostInstance = null;

        public TabSaver()
            : base()
        {
            HostInstance = this;
            //this.OnDocumentComplete += TabSaver_OnDocumentComplete;
        }

        void TabSaver_OnDocumentComplete(object pDisp, ref object url)
        {
        }


        #region Register your new browser UI elements here

        internal static List<SpicIE.Controls.IControlBase> RunOnceCOMRegistration()
        {
            Host.TraceSink.TraceEvent(TraceEventType.Information, 0, "RunOnceRegisterCOMControls");

            List<SpicIE.Controls.IControlBase> controls = new List<SpicIE.Controls.IControlBase>();
            //controls.Add(new MenuItems.MenuItemLoad());
            //controls.Add(new MenuItems.MenuItemSave());
            controls.Add(new MenuItems.MenuItemSaveAs());
            controls.Add(new MenuItems.MenuItemLoadFrom());
            controls.Add(new ToolbarButtons.LoadTabsObjectButton());
            controls.Add(new ToolbarButtons.SaveTabsObjectButton());

            return controls;
        }

        #endregion

        #region SpicIE - Required methods, do not change

        /// <summary>
        /// This function is necessary to register this plugin using the functions provided in the SpicIE.Host
        /// The function and its contents must not be changed
        /// </summary>
        /// <param name="typeToRegister"></param>
        [ComRegisterFunction]
        internal static void RegisterControls(Type typeToRegister)
        {
            SpicIE.Host.RegisterHost(typeToRegister, PLUGIN_GUID, PLUGIN_PROGID);
            SpicIE.Host.RegisterControls(RunOnceCOMRegistration());
        }

        /// <summary>
        /// This function is necessary to unregister this plugin using the functions provided in the SpicIE.Host
        /// The function and its contents must not be changed
        /// </summary>
        /// <param name="typeToRegister"></param>
        [ComUnregisterFunction]
        internal static void UnregisterControls(Type typeToRegister)
        {
            SpicIE.Host.UnregisterHost(typeToRegister, PLUGIN_GUID);
            SpicIE.Host.UnregisterControls(RunOnceCOMRegistration());
        }

        #endregion

    }
}
